import GoodsItem from './components/goods-item.vue'
export default {
	components: {
		GoodsItem
	},
	data() {
		return {
			tabs: [],
			current: 0,
			userInfo: {
				headimgurl: '',
				nickname: ''
			},
			goodsList: [],
			limit: 10,
			noticeText: '',
			randomInfo: {},
			first: false, //是否第一次请求列表
			videoUrl: ''
		};
	},
	async onLoad() {

	},
	methods: {
		// 获取公告
		async getNotice() {
			var res = await this.$get('server/index/getgonggao', {
				index: 1
			});
			if (res.errcode != 0) {
				this.$toast(res.errmsg);
				return;
			}
			this.noticeText = res.notice
		},
		// 盲盒商品列表
		async getGoodsList(pageNo, pageSize) {
			var res = await this.$get('server/index/getmanghegoods', {
				page: pageNo,
				limit: pageSize,
			});
			if (res.errcode != 0) {
				this.$toast(res.errmsg);
				this.$refs.paging.complete(false);
				return;
			}
			this.$refs.paging.complete(res.list);
			if (this.first) {
				this.getRandom(this.goodsList.length, res.list)
			}
			this.first = false
		},
		// 获取个人信息
		async getUserInfo() {
			var res = await this.$get('server/login/loaduser');
			if (res.errcode != 0) {
				this.$toast(res.errmsg);
				return;
			}
			this.userInfo = res.data.user
		},
		changeTab(index) {
			this.current = index
			this.$refs.paging.reload()
		},
		onClick(item) {
			this.$navTo('pages/manghe/detail/detail', {
				goodsId: item.id
			})
		},
		async toAgreement(type) {
			var res = await this.$get('server/login/gethtml', {
				type: type
			});
			if (res.errcode != 0) {
				this.$toast(res.errmsg);
				return;
			}
			this.videoUrl = res.data.list.text;
			this.$refs.miji.open()
			// this.$navTo('pages/mine/agreement/agreement', {
			// 	type: type
			// });
		},
		// 轮播图跳转
		onSwiperClick(item) {
			this.$navTo('pages/manghe/detail/detail', {
				goodsId: item.goods_id
			})
		},
		getRandom(max, list) {
			var rand = Math.floor(Math.random() * (max + 1));
			this.$nextTick(() => {
				this.randomInfo = list[rand]
			})
		}
	}
};
